Skip to content

chore(maintenance): avoid attaching two middlewares to ua #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 5, 2023
Merged

chore(maintenance): avoid attaching two middlewares to ua #1583

merged 1 commit into from
Jul 5, 2023

Conversation

am29d
Copy link
Contributor

@am29d am29d commented Jul 5, 2023

Description of your changes

This PR adds a check before adding user agent middleware, to avoid attaching two or more middlewares and fire a warning in the catch block. I have also refactored the tests, to make it a bit more readable.

Related issues, RFCs

Issue number: closes #1578

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@am29d am29d requested review from dreamorosi and a team July 5, 2023 15:34
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Jul 5, 2023
@boring-cyborg boring-cyborg bot added commons This item relates to the Commons Utility tests PRs that add or change tests labels Jul 5, 2023
@am29d am29d removed the request for review from a team July 5, 2023 15:35
@am29d am29d self-assigned this Jul 5, 2023
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this!

@dreamorosi dreamorosi merged commit 2eb7ab3 into aws-powertools:main Jul 5, 2023
@@ -33,6 +33,13 @@ const customUserAgentMiddleware = (feature: string) => {
// @ts-ignore
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I like ignoring things in the type system

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged and agree.

In this instance we decided to use an any as a type for the client because we didn't want to bring in the @aws-sdk/types package into the utility. This code resides in the commons utility, which is pulled in by all the other Powertools utilities.

Given that there's all the core utilities don't use any AWS SDK, using the @aws-sdk/types in this module would require customers to install it as a developer dependency when they develop or build their code using Powertools.
This is a problem because when building with TypeScript, the type-checking engine will block the compilation is the dependency is missing.

To avoid this, we decided to go for an any type (which is discouraged in our codebase - hence the @ts-ignore) and also put unit tests.

We have considered writing our own minimal Client type, and the option is still in the cards, but have decided to not include it for now given the limited scope of the feature (i.e. getting a client from a 3rd party library and calling a method on it) and the fact that we implemented the function in a way that even if you pass a random object (aka not a client) it won't throw an error but just log a warning.

I am still strongly inclined to review this type as soon as we have bandwidth and remove the ignore.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my preference would be to write our own types def.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commons This item relates to the Commons Utility size/L PRs between 100-499 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: avoid attaching two middlewares when appending UA to AWS SDK
3 participants